package com.hksj.base.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.base.entity.DeviceMetadataParseInfo;
import com.hksj.base.entity.Properties;
import com.hksj.base.query.*;
import com.hksj.base.service.DefaultDeviceService;
import com.hksj.base.vo.ChartVO;
import com.hksj.base.vo.DeviceOverviewVO;
import com.hksj.base.vo.DeviceStatusVO;
import com.hksj.base.vo.ProductDeviceOverviewVO;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "通用-设备列表")
@RestController
@RequestMapping("/api/comm/device")
public class DefaultDeviceController {
    @Autowired
    private DefaultDeviceService defaultDeviceService;

    @ApiOperation(value = "设备列表-分页查询设备列表",response = DeviceStatusVO.class)
    @PostMapping("/pageDevice")
    public Rest<Page<DeviceStatusVO>> pageDevice(@RequestBody @Validated BaseDeviceQuery query){
        Page<DeviceStatusVO> page = defaultDeviceService.pageDevice(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "大屏-分页查询当前报警设备列表(不支持排序)",response = DeviceStatusVO.class)
    @PostMapping("/pageAlarmDevice")
    public Rest<Page<DeviceStatusVO>> pageAlarmDevice(@RequestBody @Validated BaseAlarmDeviceQuery query){
        Page<DeviceStatusVO> page = defaultDeviceService.pageAlarmDevice(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "设备列表-分页查询上报历史记录",response = Properties.class)
    @PostMapping("/pageRecord")
    public Rest<Page<Properties>> pageRecord(@RequestBody @Validated BaseRecordQuery query){
        Page<Properties> page = defaultDeviceService.pageRecord(query);
        return Rest.ok(page);
    }

    @ApiOperation(value = "设备列表-查询设备各属性折线图")
    @PostMapping("/listChartData")
    public Rest<List<ChartVO>> listChartData(@RequestBody @Validated ChartQuery query){
        List<ChartVO> list = defaultDeviceService.listChartData(query);
        return Rest.ok(list);
    }

    @ApiOperation("大屏-设备概览")
    @PostMapping("/getDeviceOverview")
    public Rest<DeviceOverviewVO> getDeviceOverview(@RequestBody @Validated DeviceOverviewQuery query){
        DeviceOverviewVO res = defaultDeviceService.getDeviceOverview(query);
        return Rest.ok(res);
    }

    @ApiOperation("大屏-设备概览(按产品分类)")
    @PostMapping("/listProductDeviceOverview")
    public Rest<List<ProductDeviceOverviewVO>> listProductDeviceOverview(@RequestBody @Validated DeviceOverviewQuery query){
        List<ProductDeviceOverviewVO> res = defaultDeviceService.listProductDeviceOverview(query);
        return Rest.ok(res);
    }

    @ApiOperation(value = "设备信息-设备当前属性")
    @PostMapping("/getDeviceCurrentProperty/{deviceId}")
    public Rest<DeviceStatusVO> getDeviceCurrentProperty(@PathVariable String deviceId){
        DeviceStatusVO device = defaultDeviceService.getDeviceCurrentProperty(deviceId);
        return Rest.ok(device);
    }
}
